package farmaciaweb.com.br.entity;

import java.io.Serializable;
import java.lang.String;
import java.util.Collection;
import javax.persistence.*;

import static javax.persistence.GenerationType.SEQUENCE;

/**
 * Entity implementation class for Entity: Laboratorio
 *
 */
@Entity
@NamedQueries(value = {
		@NamedQuery(name = "bd_farmaciaweb.consultaLaboratorio", query = "SELECT e FROM Laboratorio e " +
																"where (e.nome like :nome) " + 
																" and ((e.cnpj = :cnpj) OR ('' = :cnpj))")})
public class Laboratorio implements Serializable{

	   
	/**
	 * 
	 */
	private static final long serialVersionUID = 8380710264806734096L;

	@Id
	@Column(name="idLaboratorio")
	@GeneratedValue(strategy = SEQUENCE, generator = "lab_gen")
	@SequenceGenerator(name = "lab_gen", sequenceName = "lab_seq", allocationSize = 5)
	private int idLaboratorio;
	
	@Column(nullable = false, length = 14, unique = true)
	private String cnpj;
	
	@Column(nullable = false, length = 50)
	private String nome;
	
	@Column(nullable = false, length = 80)
	private String endereco;
	
	@Column(nullable = false, length = 10)
	private String telefone;
	
	@Column(nullable = false, length = 80, unique = true)
	private String email;
	
	@Column(length = 100)
	private String homepage;
	
	@OneToMany(mappedBy = "laboratorio")
	private Collection<Medicamento> medicamento;
	
	@OneToMany(mappedBy = "laboratorio")
	private Collection<Lote> lote;
	
	//@OneToMany(mappedBy = "laboratorio")
	//private Collection<Preco> genericosLab;

	public Laboratorio() {
		super();
	}   
	public int getIdLaboratorio() {
		return this.idLaboratorio;
	}

	public void setIdLaboratorio(int idLaboratorio) {
		this.idLaboratorio = idLaboratorio;
	}   
	public String getCnpj() {
		return this.cnpj;
	}

	public void setCnpj(String cnpj) {
		this.cnpj = cnpj;
	}   
	
	public String getNome() {
		return this.nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}   
	public String getEndereco() {
		return this.endereco;
	}

	public void setEndereco(String endereco) {
		this.endereco = endereco;
	}   
	public String getTelefone() {
		return this.telefone;
	}

	public void setTelefone(String telefone) {
		this.telefone = telefone;
	}   
	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}   
	public String getHomepage() {
		return this.homepage;
	}

	public void setHomepage(String homepage) {
		this.homepage = homepage;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((cnpj == null) ? 0 : cnpj.hashCode());
		result = prime * result + ((email == null) ? 0 : email.hashCode());
		result = prime * result + idLaboratorio;
		result = prime * result
				+ ((medicamento == null) ? 0 : medicamento.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Laboratorio other = (Laboratorio) obj;
		if (cnpj == null) {
			if (other.cnpj != null)
				return false;
		} else if (!cnpj.equals(other.cnpj))
			return false;
		if (email == null) {
			if (other.email != null)
				return false;
		} else if (!email.equals(other.email))
			return false;
		if (idLaboratorio != other.idLaboratorio)
			return false;
		if (medicamento == null) {
			if (other.medicamento != null)
				return false;
		} else if (!medicamento.equals(other.medicamento))
			return false;
		return true;
	}
		
}
